<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<html lang="zh-cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="renderer" content="webkit">
<title></title>
<link rel="stylesheet" href="css/pintuer.css">
<link rel="stylesheet" href="css/admin.css">
<script src="js/jquery.js"></script>
<script src="js/pintuer.js"></script>
</head>
<script type="text/javascript">

function queryUser(){
	$("#uid").empty();
	var url = "shiro/queryuser";
	$.ajax({
	    type: "get",
	    url: url,
	    data: "",
	    cache: false,
	    async : false,
	    dataType: "json",
	    success: function (data,textStatus){
	    	var array  = eval(data);
	   		var row = $("#uid");
	        var tda = $("<option value=''>请选择用户</option>");
	        row.append(tda);
  	        for(var i=0;i<array.length;i++){
  	        	var op = $("<option value='"+array[i]+"'>"+array[i]+"</option>");
 	            row.append(op);
	        }	
    	}  
	 });
}

function changerole(){
	 $("input[type='checkbox']").attr("checked",false);
	 var op = $("#uid").find("option:selected").val();
	 $.ajax({
		    type: "get",
		    url: "shiro/queryroles",
		    data: "user="+op,
		    cache: false,
		    async : false,
		    dataType: "json",
		    success: function (data,textStatus){
		    	var array  = eval(data);
	  	        for(var i=0;i<array.length;i++){
	  	        	if("admin"==array[i]){
	  	        		$(":checkbox[id='role1']").prop("checked",true);
	  	        	}else if("business"==array[i]){
	  	        		$(":checkbox[id='role2']").prop("checked",true);
	  	        	}else if("user"==array[i]){
	  	        		$(":checkbox[id='role3']").prop("checked",true);
	  	        	}
		        }	
	    	}  
	 });	 
}
</script>
<body onload="queryUser()">
<div class="panel admin-panel">
  <div class="panel-head" id="add"><strong><span class="icon-pencil-square-o"></span>角色维护</strong></div>
  <div class="body-content">
    <form method="post" class="form-x" action="shiro/updateroles">  
      
        <div class="form-group">
          <div class="label">
            <label>用户：</label>
          </div>
          <div class="field">
            <select id="uid" name="uid" class="input w50" onchange="changerole()">
            </select>
          </div>
        </div>
        <div class="form-group">
          <div class="label">
            <label>角色名称：</label>
          </div>
          <div class="field" style="padding-top:8px;"> 
            admin <input id="role1" value="admin" name="role" type="checkbox"/>
            business <input id="role2"  value="business" name="role" type="checkbox" />
            user <input id="role3"  value="user" name="role" type="checkbox" /> 
          </div>
        </div>
    
      <div class="form-group">
        <div class="label">
          <label></label>
        </div>
        <div class="field">
          <button class="button bg-main icon-check-square-o" type="submit"> 提交</button>
        </div>
      </div>
    </form>
  </div>
</div>

</body></html>